var ExtractTextPlugin = require('extract-text-webpack-plugin');
var utils = require('./utils');
var outputFor = 'src';
const px2rem = require('postcss-px2rem')
const cssnext = require('postcss-cssnext')({
  browsers: [
    'last 2 versions',
    'iOS >= 7',
    'Android >= 4.0',
  ],
});
var devLoaders = [{
        test: /\.ts$/,
        exclude: [/\.spec\.ts$/],
        loaders: [
                'awesome-typescript-loader',
                'angular2-router-loader',
                'angular2-template-loader'
            ]
    },
    {
        test: /\.html$/,
        exclude: utils.root('src', 'index.html'),
        loader: 'raw-loader'
    },
    {
        test: /\.css$/,
        include: [utils.root('src'), /codemirror/],
        exclude: utils.root('src', 'assets'),
        loader: ['to-string-loader', 'css-loader'] //raw-loader只针对.css文件
    },
    {
        test: /\.scss$/,
        exclude: utils.root(outputFor, 'assets'),
        use: [
            { loader: 'to-string-loader' },
            { loader: 'css-loader', options: { importLoaders: 2 } }, //2代表css-loader后还需要几个loader
            { loader: 'postcss-loader', options: { plugins: [
                require("autoprefixer")("last 100 versions"),
                cssnext,
                px2rem({ remUnit: 75 })
            ] } },
            { loader: 'sass-loader' }
        ]
    },
    {
        test: /\.scss$/,
        loader: ExtractTextPlugin.extract({
            fallback: 'style-loader',
            use: ['css-loader', 'sass-loader'],
            publicPath: '../'
        }),
        include: utils.root(outputFor, 'assets'),
        exclude: /\.useable\.scss$/,
    },
    {
        test: /\.(woff|woff2|ttf|eot|svg|map)$/,
        loader: 'file-loader',
        options: {
            name: '[name].[ext]',
            outputPath: 'assets/'
        }
    },
    {
        test: /\.(jpg|png|gif)$/,
        loader: 'url-loader',
        options: {
            limit: 5,
            name: '[name].[ext]',
            outputPath: 'assets/'
        }
    }
];
module.exports = devLoaders;